package com.faxsun.web.utils;

import javax.servlet.http.HttpSession;

import mblog.web.controller.BaseController;
import mtons.modules.lang.Const;
import mtons.modules.pojos.UserProfile;

import com.faxsun.web.pojos.FSUserProfile;

/**
 * 设置或使Session失效
 * 
 * @author songdragon 2015年6月19日
 *
 */
public class SessionUtils {

	/**
	 * 设置登录信息{@link BaseController#putProfile}
	 * 
	 * @param session
	 * @param user
	 */
	public static void putProfile(HttpSession session, UserProfile user) {
		putProfile(session, user, Boolean.FALSE);
	}

	public static void putProfile(HttpSession session, UserProfile user,
			boolean isLocal) {
		session.setAttribute(Const.KEY_LOGIN, user);
		
		if (!isLocal) {
			// 设置电商需要的登录信息
			if (user != null) {
				FSUserProfile fsUser = (FSUserProfile) user;
				session.setAttribute("_blc_overrideCustomerId",
						fsUser.getUserId());
				session.setAttribute("OK_TO_USE_SESSION", Boolean.TRUE);
				session.setAttribute("info_first_login", Boolean.TRUE);
			} else {
				session.removeAttribute("info_first_login");
				session.removeAttribute("_blc_overrideCustomerId");
			}
		}
	}
}
